package com.daqian.mall.service;

import com.daqian.mall.entity.ModuleGoodsTag;
import com.daqian.mall.mapper.ModuleGoodsTagMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class TagService {

    @Resource
    private ModuleGoodsTagMapper moduleGoodsTagMapper;

    /**
     * 根据id获取详情
     *
     * @param id
     * @return
     */
    public ModuleGoodsTag getById(Long id) {
        return moduleGoodsTagMapper.getById(id);
    }

    /**
     * 获取所有标签
     *
     * @return
     */
    public List<ModuleGoodsTag> listAllTag() {
        return moduleGoodsTagMapper.selectAll();
    }

    /**
     * 新增标签
     *
     * @return
     */
    public void saveTag(ModuleGoodsTag entity) {
        entity.setId(null);
        moduleGoodsTagMapper.insertSelective(entity);
    }

    /**
     * 修改标签
     *
     * @return
     */
    public void updateTag(ModuleGoodsTag entity) {
        moduleGoodsTagMapper.updateByPrimaryKeySelective(entity);
    }

    /**
     * 删除单个标签
     *
     * @return
     */
    public void deleteTag(Long id) {
        moduleGoodsTagMapper.deleteByPrimaryKey(id);
    }

    /**
     * 删除多个标签
     *
     * @return
     */
    @Transactional(rollbackFor = RuntimeException.class)
    public void deleteTag(Long[] ids) {
        for (Long id : ids) {
            moduleGoodsTagMapper.deleteByPrimaryKey(id);
        }
    }
}


